package com.tingyuge.base.thread.wang.chapter6;

/**
 * 有一个静态方法 是因为 函数式编程获取不到当前的对象,只能Thread.isInterrupt
 */
public class ThreadInterruptByWait {

    private static  Object object =new Object();
    public static void main(String[] args) throws InterruptedException {

       final Thread t1 = new Thread(()->{
         while (true){
             synchronized (object){
                 try {
                     object.wait();
                 } catch (InterruptedException e) {
                     System.out.println("wait 中断");
                     e.printStackTrace();
                 }
             }
         }
        });
        t1.start();
        Thread.sleep(1000);
        System.out.println(t1.isInterrupted());
        t1.interrupt();
        System.out.println(t1.isInterrupted());
    }
}
